import { computed, type Ref } from 'vue'
import { add, toFixed } from '@/utils/math'

export function useTotalPrice(
  baiduPrice: Ref<number | string | undefined>,
  qihu360Price: Ref<number | string | undefined>,
  creativePrice: Ref<number | string | undefined>,
  creativeSelect: Ref<boolean>,
  qihu360Select: Ref<boolean>
) {
  return computed(() => {
    const picturePrice = creativeSelect.value ? Number(creativePrice.value) : 0
    const qihu360Price = qihu360Select.value ? Number(qihu360Select.value) : 0
    const price = add(qihu360Price, add(baiduPrice.value || 0, picturePrice))

    if (price.toNumber() !== 0) {
      return toFixed(0, price)
    } else {
      return '--'
    }
  })
}
